home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1995 October / EnigmA AMIGA RUN 01 (1995)(G.R. Edizioni)(IT)[!][issue 1995-10][Aminet 7].iso / Aminet / util / misc / GadMget1_95.lha / GadMget / GadMGet.source.lha / mget_listview2.c < prev    next >
C/C++ Source or Header  |  1995-02-02  |  21KB  |  709 lines

  1. #ifndef MGET_LISTVIEW2_C
  2. #define MGET_LISTVIEW2_C
  3.  
  4. /*
  5.  *  Source machine generated by GadToolsBox V2.0b
  6.  *  which is (c) Copyright 1991-1993 Jaba Development
  7.  *
  8.  *  GUI Designed by : Jeremy Friesner
  9.  */
  10.  
  11. #include <exec/types.h>
  12. #include <exec/libraries.h>
  13. #include <intuition/intuition.h>g
  14. #include <intuition/classes.h>
  15. #include <intuition/classusr.h>
  16. #include <intuition/imageclass.h>
  17. #include <intuition/gadgetclass.h>
  18. #include <libraries/gadtools.h>
  19. #include <graphics/displayinfo.h>
  20. #include <graphics/gfxbase.h>
  21. #include <clib/exec_protos.h>
  22. #include <clib/intuition_protos.h>
  23. #include <clib/gadtools_protos.h>
  24. #include <clib/graphics_protos.h>
  25. #include <clib/utility_protos.h>
  26. #include <clib/wb_protos.h>
  27.  
  28. #include <workbench/workbench.h>
  29. #include <workbench/startup.h>
  30. #include <string.h>
  31.  
  32. #include "mget_listview2.h"
  33. #include "Gadmget.h"
  34.  
  35. #define BACKSPACE_KEYCODE 8
  36. #define UP_KEYCODE        76
  37. #define DOWN_KEYCODE      77
  38. #define LEFT_KEYCODE      79
  39. #define RIGHT_KEYCODE     78
  40.  
  41. extern char pnamestring[];
  42. extern struct List *filelist;
  43. extern struct List *getlist;
  44. extern struct Gadget *findgadlist;
  45. extern void *findvi;
  46. extern int appwindow;
  47. extern char *pubscreenname;
  48. extern int screentype;
  49. extern UWORD windowwidth;
  50. extern UWORD windowheight;
  51. extern UWORD windowtop;
  52. extern UWORD windowleft;
  53. extern char windowtitle[];
  54. extern int windowisopen;
  55. extern int screenisopen;
  56. extern char sListFontName[];
  57. extern char sOutFileName[];
  58. extern int nListFontSize;
  59. int screenwidth,screenheight;
  60. extern FILE *fpOut;
  61. extern struct TextFont *listfontdata;  /* pointer to font data */
  62. extern struct GfxBase *GraphicsBase;        /* needed to determine default system font */
  63. extern BOOL BStartedFromWB;
  64. extern int nTopListTop;
  65. extern int nTopListHeight;
  66. extern int nBottomListHeight;
  67. extern int filelist_length;
  68. extern int getlist_length;
  69.     
  70.  
  71. struct Screen        *Scr = NULL;
  72. APTR                 VisualInfo = NULL;
  73. struct Window        *mgetWnd = NULL;
  74. struct Window            *findwindow = NULL;
  75. struct AppWindow        *appwin = NULL;
  76. struct AppMessage        *amsg = NULL;
  77. struct MsgPort         *awport = NULL;
  78. struct Gadget        *mgetGList = NULL;
  79. struct Menu          *mgetMenus = NULL;
  80. struct IntuiMessage  mgetMsg;
  81. struct Gadget        *mgetGadgets[2];
  82. UWORD                mgetLeft = 0;
  83. UWORD                mgetTop = 12;
  84. UWORD lastcode;
  85. ULONG appwinsig = 0L;
  86.  
  87. struct TextAttr topaz8 = {
  88.     ( STRPTR )"topaz.font", 8, 0x00, 0x00 };
  89.  
  90. struct TextAttr listfont = {
  91.     NULL, 0 , 0x00, 0x00 };
  92.  
  93. struct NewMenu mgetNewMenu[] = {
  94.  NM_TITLE, "Project",                 NULL, 0L,           NULL, NULL,
  95.     NM_ITEM, "Open",                 "O",     0,           0L, (APTR)mgetopenfile,
  96.     NM_ITEM, "Append",                 "A",     0,           0L, (APTR)mgetappend,
  97.     NM_ITEM, "Clear",                 NULL, 0L,        NULL, NULL,
  98.      NM_SUB,  "Files List",           "U",  0,         0L, (APTR)mgetclearfiles,
  99.      NM_SUB,  "Get List",             "I",  0,         0L, (APTR)mgetclearget,
  100.     NM_ITEM, "About",                 NULL, 0,           0L, (APTR)mgetabout,
  101.     NM_ITEM, (STRPTR)NM_BARLABEL,     NULL, 0L,           0L, NULL,
  102.     NM_ITEM, "Quit",                 "Q",     0,           0L, (APTR)mgetquit,
  103.  NM_TITLE,"Find",                     NULL, 0L,           NULL, NULL,
  104.     NM_ITEM, "Find Forward",        "F",     0,           0L, (APTR)mgetfind,
  105.    NM_ITEM, "Find Backward",         "K",     0,           0L, (APTR)mgetfindback,
  106.    NM_ITEM, "Find from Top",         "T",     0,           0L, (APTR)mgetfindtop,
  107.    NM_ITEM, "Find from Bottom",     "B",     0,           0L, (APTR)mgetfindbottom,
  108.     NM_ITEM, "Find Next",             "N",     0,           0L, (APTR)mgetfindnext,
  109.    NM_ITEM, "Find Previous",         "P",     0,           0L, (APTR)mgetfindprevious, 
  110.    NM_ITEM, "Find Current",            "J",  0,              0L, (APTR)mgetfindcurrent,
  111.    NM_ITEM, "Select Multiple",       "S",  0L,          NULL, (APTR)mgetmultiselect,
  112.    NM_ITEM, "Deselect Multiple",    "D",  0L,          NULL, (APTR)mgetmultideselect,
  113.     NM_ITEM, "Case Sensitive",         "C",     0|CHECKIT, 0L, (APTR)mgetcase,
  114.  NM_TITLE,"Sort",                     NULL, 0L,           NULL, NULL,
  115.    NM_ITEM, "Files List",             NULL, 0L,           NULL, NULL,
  116.     NM_SUB,  "By Directory",         "!",     0L,           NULL, (APTR)mgetfilesbydir,
  117.     NM_SUB,  "By Size",             "@",     0L,           NULL, (APTR)mgetfilesbysize,
  118.     NM_SUB,  "By FileName",         "#",     0L,           NULL, (APTR)mgetfilesbyname,
  119.     NM_SUB,  "By Description",         "$",     0L,           NULL, (APTR)mgetfilesbydesc,
  120.     NM_SUB,  "By Age",                "%",    0L,              NULL, (APTR)mgetfilesbyage,
  121.     NM_SUB,  "Keep Sorted",         "-", 0|CHECKIT, 0L, (APTR) mgetfileskeep,
  122.     NM_ITEM, "Get List",             NULL, 0L,           NULL, NULL,
  123.     NM_SUB,  "By Directory",         "1",     0L,           NULL, (APTR)mgetgetbydir,
  124.     NM_SUB,  "By Size",             "2",     0L,           NULL, (APTR)mgetgetbysize,
  125.     NM_SUB,  "By FileName",         "3",     0L,           NULL, (APTR)mgetgetbyname,
  126.     NM_SUB,  "By Description",         "4",     0L,           NULL, (APTR)mgetgetbydesc,
  127.     NM_SUB,  "By Age",                "5",    0L,              NULL, (APTR)mgetgetbyage,
  128.     NM_SUB,  "Keep Sorted",         "=",    0|CHECKIT, 0L, (APTR) mgetgetkeep,
  129.    NM_ITEM, "Sort Algorithm",         NULL, 0L,           NULL, NULL,
  130.     NM_SUB,  "Tree Sort",             NULL, 0|CHECKIT, 0L, (APTR)mgettreesort,
  131.     NM_SUB,  "Bubble Sort",         NULL, 0|CHECKIT, 0L, (APTR)mgetbubblesort,
  132.    NM_ITEM, "Case Sensitive",         "E",     0|CHECKIT, 0L, (APTR)mgetsortcase,
  133.  NM_TITLE,"Output",                 NULL, 0L,           NULL, NULL,
  134.      NM_ITEM, "Aminet Parse",         NULL, 0|CHECKIT, 0L, (APTR)mgetnoparse,
  135.      NM_ITEM, "Get Files",             NULL, 0|CHECKIT, 0L, (APTR)mgetfiles,
  136.     NM_ITEM, "Get Readmes",         NULL, 0|CHECKIT, 0L, (APTR)mgetreadmes,
  137.     NM_ITEM, "Split Commands",         NULL, 0|CHECKIT, 0L, (APTR)mgetsplit,
  138.    NM_ITEM, "Simple Paths",         NULL, 0|CHECKIT, 0L, (APTR)mgetCD,
  139.      NM_ITEM, "Line Length...",         "L",     0,           0L, (APTR)mgetlinelength,
  140.    NM_ITEM, "Output Now",             "Y",     0,           0L, (APTR)mgetoutput,
  141.    NM_ITEM, "Output To...",         "R",     0,           0L, (APTR)mgetoutputfile,
  142.     NM_END,  NULL,                     NULL, 0,           0L, NULL };
  143.  
  144. char GadgetTextString0[] = "";
  145.  
  146. struct NewGadget mgetNGad[] = {
  147.     0, 0, 0, 0, (UBYTE *)"Selectable Files", NULL, 0, PLACETEXT_ABOVE, NULL, (APTR)listviewgadgetClicked,
  148.     0, 0, 0, 0, (UBYTE *)"Selected Files",   NULL, 1, PLACETEXT_BELOW, NULL, (APTR)list2Clicked
  149. };
  150.  
  151. ULONG mgetGTags[] = {
  152.     (GT_Underscore), '_', 
  153.     (TAG_DONE)
  154. };
  155.  
  156. UWORD DriPens[] = {
  157.     ~0 };
  158.  
  159.  
  160.  
  161.  
  162.  
  163.  
  164. int SetupScreen( void )
  165. {
  166. ULONG lflag = 0L;
  167. struct Screen *sTemp = NULL;
  168. struct DrawInfo *screen_drawinfo = NULL;
  169.     
  170.     Scr = NULL;
  171.         
  172.     switch (screentype)
  173.         {
  174.         case USE_PUBSCREEN:
  175.             Scr = LockPubScreen(pubscreenname);
  176.             if (Scr == NULL)
  177.                 {
  178.                 MakeReq("Couldn't lock public screen!",NULL,"Huh?"); 
  179.                 return(1L);
  180.                 }
  181.             screenwidth     = Scr->Width;
  182.             screenheight    = Scr->Height;
  183.             break;
  184.             
  185.         case USE_CUSTOMSCREEN:
  186.          if ((sTemp = LockPubScreen("Workbench")) != NULL)
  187.             {
  188.             lflag = GetVPModeID(&(sTemp->ViewPort));    
  189.             screenwidth  = sTemp->Width;
  190.             screenheight = sTemp->Height;
  191.             }
  192.             else
  193.             {
  194.             screenwidth  = 640;
  195.             screenheight = 400;
  196.             lflag = HIRESLACE_KEY;
  197.             }
  198.            
  199.          if (sTemp != NULL) UnlockPubScreen(NULL,sTemp);
  200.             
  201.          if ( ! ( Scr = OpenScreenTags(NULL, 
  202.                          SA_Left,            0,
  203.                         SA_Top,            0,
  204.                         SA_Width,        screenwidth,
  205.                         SA_Height,        screenheight,
  206.                         SA_Depth,        2,
  207.                         SA_Font,            NULL /* &GraphicsBase->DefaultFont */,
  208.                         SA_Type,            CUSTOMSCREEN,
  209.                         SA_DisplayID,    lflag,
  210.                         SA_AutoScroll,    TRUE,
  211.                         SA_Overscan,    OSCAN_TEXT,
  212.                         SA_Pens,            &DriPens[0],
  213.                         SA_Title,        pnamestring,
  214.                         TAG_DONE ))) 
  215.                                 return( 1L );
  216.             break;
  217.             
  218.         case USE_WBSCREEN:
  219.             Scr = LockPubScreen("Workbench");
  220.             if (Scr == NULL) {MakeReq("Couldn't lock Workbench Screen!",NULL,"Where is it?"); return(1L);}
  221.             screenwidth = Scr->Width;
  222.             screenheight = Scr->Height;
  223.             break;
  224.         }
  225.         
  226.     if ( ! ( VisualInfo = GetVisualInfo( Scr, TAG_DONE )))
  227.         return( 2L );
  228.  
  229.     return( 0L );
  230. }
  231.  
  232.  
  233.  
  234.  
  235.  
  236.  
  237.  
  238. void CloseDownScreen( void )
  239. {
  240.     if ( VisualInfo ) 
  241.         {
  242.         FreeVisualInfo( VisualInfo );
  243.         VisualInfo = NULL;
  244.         }
  245.  
  246.     switch(screentype)
  247.         {
  248.         case USE_CUSTOMSCREEN:
  249.             CloseScreen( Scr );
  250.             Scr = NULL;
  251.             break;
  252.         case USE_PUBSCREEN:
  253.             UnlockPubScreen(NULL,Scr);
  254.             break;
  255.         case USE_WBSCREEN:
  256.             UnlockPubScreen(NULL,Scr);
  257.             break;
  258.         }
  259.     
  260.     screenisopen = 0;        
  261. }    
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268.  
  269.  
  270.  
  271. int HandlemgetIDCMP( void )
  272. {
  273.     struct IntuiMessage    *m;
  274.     struct MenuItem        *n;
  275.     int            (*func)();
  276.     int     index1, index2, nMoveIncrement = 1;
  277.     BOOL            running = TRUE, BMoveTopBottom = FALSE;
  278.     WORD        wtop = -1 , wleft = -1, wheight = -1 , wwidth= -1;
  279.     
  280.     struct NewGadget ng;
  281.     struct Gadget    *g;
  282.     int FilesWindowHeightLines = nTopListHeight/(listfont.ta_YSize);
  283.     int GetWindowHeightLines = nBottomListHeight/(listfont.ta_YSize)-2;
  284.     int nTemp;
  285.     
  286.     if (GetWindowHeightLines < 1) GetWindowHeightLines = 1;  /* a little less due to round-off error in Gadget */
  287.     
  288.     while( m = GT_GetIMsg( mgetWnd->UserPort )) {
  289.  
  290.         CopyMem(( char * )m, ( char * )&mgetMsg, (long)sizeof( struct IntuiMessage ));
  291.         lastcode = m->Code;
  292.         
  293.         GT_ReplyIMsg( m );
  294.  
  295.         if ((mgetMsg.Qualifier & IEQUALIFIER_LSHIFT)||
  296.              (mgetMsg.Qualifier & IEQUALIFIER_RSHIFT)) nMoveIncrement = FilesWindowHeightLines;
  297.              
  298.         if (mgetMsg.Qualifier & IEQUALIFIER_CONTROL)  nMoveIncrement = 10;
  299.         
  300.         if ((mgetMsg.Qualifier & IEQUALIFIER_LALT)||
  301.             (mgetMsg.Qualifier & IEQUALIFIER_RALT)) BMoveTopBottom = TRUE;
  302.         
  303.         switch ( mgetMsg.Class ) {
  304.             case IDCMP_RAWKEY:
  305.                 /* printf("[%i:%c]\n", mgetMsg.Code, mgetMsg.Code); */
  306.                     
  307.                 if (BMoveTopBottom == FALSE)            
  308.                 {
  309.                     switch ( mgetMsg.Code ) {
  310.                         case UP_KEYCODE:
  311.                             nTemp = ListViewTop((struct Gadget *) mgetGadgets[0], filelist);
  312.                             if (nTemp > (nMoveIncrement-1)) nTemp -= nMoveIncrement; else nTemp = 0;
  313.                             GT_SetGadgetAttrs((struct Gadget *) mgetGadgets[0], mgetWnd, NULL, GTLV_Top, nTemp, TAG_END);                
  314.                             break;
  315.                         
  316.                         case DOWN_KEYCODE:
  317.                             GT_SetGadgetAttrs((struct Gadget *) mgetGadgets[0], mgetWnd, NULL, GTLV_Top, 
  318.                                                      ListViewTop((struct Gadget *) mgetGadgets[0], filelist) + nMoveIncrement
  319.                                                         , TAG_END);                
  320.                             break;
  321.                         
  322.                         case LEFT_KEYCODE:
  323.                             nTemp = ListViewTop((struct Gadget *) mgetGadgets[1], getlist);
  324.                             if (nMoveIncrement == FilesWindowHeightLines) nMoveIncrement = GetWindowHeightLines;
  325.                             if (nTemp > (nMoveIncrement-1)) nTemp -= nMoveIncrement; else nTemp = 0;
  326.                             GT_SetGadgetAttrs((struct Gadget *) mgetGadgets[1], mgetWnd, NULL, GTLV_Top, nTemp, TAG_END);                
  327.                             break;
  328.         
  329.                         case RIGHT_KEYCODE:
  330.                             if (nMoveIncrement == FilesWindowHeightLines) nMoveIncrement = GetWindowHeightLines;
  331.                             GT_SetGadgetAttrs((struct Gadget *) mgetGadgets[1], mgetWnd, NULL, GTLV_Top, 
  332.                                                      ListViewTop((struct Gadget *) mgetGadgets[1], getlist) + nMoveIncrement
  333.                                                         , TAG_END);                
  334.                             break;                
  335.                         }
  336.                 }
  337.                 else
  338.                 {
  339.                     /* ALT held down--go to top or bottom of appropriate list */
  340.                     switch ( mgetMsg.Code ) {
  341.                         case UP_KEYCODE:
  342.                             GT_SetGadgetAttrs((struct Gadget *) mgetGadgets[0], mgetWnd, NULL, GTLV_Top, 0, TAG_END);                
  343.                             break;
  344.  
  345.                         case DOWN_KEYCODE:
  346.                             GT_SetGadgetAttrs((struct Gadget *) mgetGadgets[0], mgetWnd, NULL, GTLV_Top, filelist_length, TAG_END);    
  347.                             break;
  348.  
  349.                         case LEFT_KEYCODE:
  350.                             GT_SetGadgetAttrs((struct Gadget *) mgetGadgets[1], mgetWnd, NULL, GTLV_Top, 0, TAG_END);                
  351.                             break;
  352.  
  353.                         case RIGHT_KEYCODE:
  354.                             GT_SetGadgetAttrs((struct Gadget *) mgetGadgets[1], mgetWnd, NULL, GTLV_Top, getlist_length, TAG_END);
  355.                             break;
  356.                     }
  357.                 }
  358.                 break;
  359.                 
  360.             case IDCMP_VANILLAKEY:
  361.                 /* printf("{%i:%c}\n", mgetMsg.Code, mgetMsg.Code); */
  362.                                 
  363.                 switch ( mgetMsg.Code ) {
  364.                     case ' ':
  365.                         GT_SetGadgetAttrs((struct Gadget *) mgetGadgets[0], mgetWnd, NULL, GTLV_Top, 
  366.                             ListViewTop((struct Gadget *) mgetGadgets[0], filelist) + FilesWindowHeightLines, TAG_END);
  367.                     break;
  368.                     
  369.                     case BACKSPACE_KEYCODE:
  370.                         nTemp = ListViewTop((struct Gadget *) mgetGadgets[0], filelist) - FilesWindowHeightLines;
  371.                         if (nTemp < 0) nTemp = 0;
  372.                         GT_SetGadgetAttrs((struct Gadget *) mgetGadgets[0], mgetWnd, NULL, GTLV_Top, nTemp, TAG_END);                
  373.                     break;                    
  374.                 }
  375.                 break;
  376.                 
  377.             case IDCMP_REFRESHWINDOW:
  378.                 GT_BeginRefresh( mgetWnd );
  379.                 GT_EndRefresh( mgetWnd, TRUE );
  380.                 break;
  381.  
  382.             case IDCMP_NEWSIZE:
  383.                 windowtop = mgetWnd->TopEdge;
  384.                 windowleft = mgetWnd->LeftEdge;
  385.                 windowheight = mgetWnd->Height;
  386.                 windowwidth = mgetWnd->Width;
  387.                 
  388.                 index1 = ListViewTop ((struct Gadget *) mgetGadgets[0], mgetWnd);
  389.                 index2 = ListViewTop ((struct Gadget *) mgetGadgets[1], mgetWnd);
  390.  
  391.                 RemoveGList(mgetWnd, mgetGList, -1);
  392.                 FreeGadgets(mgetGList);
  393.                 
  394.                 EraseRect(mgetWnd->RPort,mgetWnd->BorderLeft, mgetWnd->BorderTop,
  395.                             mgetWnd->Width - mgetWnd->BorderRight - 1,
  396.                             mgetWnd->Height - mgetWnd->BorderBottom - 1);
  397.                             
  398.                 if (SetupGadgets(g, &ng) == 2L) 
  399.                     {
  400.                     MakeReq("ListView Gadget Setup Error",NULL,"I wish Jeremy would debug better");
  401.                     CleanUp();
  402.                     exit(10);
  403.                     }
  404.                 AddGList(mgetWnd, mgetGList, -1, -1, NULL);
  405.                 RefreshGList(mgetGList, mgetWnd, NULL, -1);
  406.                         
  407.                 GT_RefreshWindow(mgetWnd, NULL);
  408.                 RefreshWindowFrame(mgetWnd);
  409.                 
  410.                 ChangeWindowTitle();                
  411.                 
  412.                 
  413.                 GT_SetGadgetAttrs((struct Gadget *) mgetGadgets[0], mgetWnd, NULL, GTLV_Labels, filelist, GTLV_Top, index1, TAG_END); 
  414.                 GT_SetGadgetAttrs((struct Gadget *) mgetGadgets[1], mgetWnd, NULL, GTLV_Labels, getlist, GTLV_Top, index2, TAG_END); 
  415.                 break;
  416.                 
  417.             case    IDCMP_CLOSEWINDOW:
  418.                 running = mgetCloseWindow();
  419.                 break;
  420.  
  421.             case    IDCMP_GADGETUP:
  422.             case    IDCMP_GADGETDOWN:
  423.                 func = ( void * )(( struct Gadget * )mgetMsg.IAddress )->UserData;
  424.                 running = func();
  425.                 break;
  426.  
  427.             case    IDCMP_MENUPICK:
  428.                 while( mgetMsg.Code != MENUNULL ) {
  429.                     n = ItemAddress( mgetMenus, mgetMsg.Code );
  430.                     func = (void *)(GTMENUITEM_USERDATA( n ));
  431.                     running = func();
  432.                     mgetMsg.Code = n->NextSelect;
  433.                 }
  434.                 break;
  435.         }
  436.     }
  437.     return( running );
  438. }
  439.  
  440.  
  441.  
  442.  
  443.  
  444. int SetupGadgets(struct Gadget *gadlist, struct NewGadget *ng)
  445. {
  446.  UWORD        lc, tc;
  447.  UWORD        offx = Scr->WBorLeft, offy = Scr->WBorTop + Scr->RastPort.TxHeight + 1;
  448.  UWORD        wheight = windowheight - offy;
  449.  UWORD        wwidth  = windowwidth  - offx;
  450.  UWORD        topedge[2], height[2];
  451.  BYTE           bSizeGadHeight = 8;        
  452.  struct List      *thislist = NULL; 
  453.            
  454.  topedge[0]    = offy;
  455.  height[0]     = ((int) (.7 * wheight));
  456.  topedge[1]    = topedge[0] + height[0] + 1;
  457.  height[1]     = windowheight - topedge[1] - bSizeGadHeight - 2;
  458.  
  459.     nTopListTop = topedge[0];
  460.     nTopListHeight = height[0];
  461.     nBottomListHeight = height[1];
  462.     
  463.     /* Put in correct font */
  464.     listfont.ta_Name  = sListFontName;
  465.     if (nListFontSize > 0) listfont.ta_YSize = nListFontSize; else listfont.ta_YSize = 12;
  466.     /* a reasonable default, hopefully! */
  467.     listfontdata = OpenDiskFont(&listfont);    
  468.     if (listfontdata == NULL)
  469.      {
  470.          /* load system default font */
  471.         AskFont(&Scr->RastPort,&listfont);
  472.         listfontdata = OpenDiskFont(&listfont);
  473.         if (listfontdata == NULL)
  474.              {
  475.              MakeReq("Couldn't open default font!",NULL,"Something's weird here...");
  476.              CleanUp();
  477.              exit(5);
  478.              }
  479.              if (strlen(sListFontName) > 0) 
  480.         {
  481.             MakeReq("Couldn't find specified font, Sorry!",NULL,"Um, Ok");
  482.             strncpy(sListFontName,NUL,1);
  483.             nListFontSize = listfont.ta_YSize;
  484.         }
  485.      }
  486.            
  487.     if ( ! ( gadlist = CreateContext( &mgetGList )))
  488.         return( 1L );
  489.  
  490.     for( lc = 0, tc = 0; lc < mget_CNT; lc++ ) 
  491.         {
  492.         
  493.         if (lc == 1) 
  494.             {
  495.             thislist = getlist;
  496.             }
  497.             else 
  498.             {
  499.             thislist = filelist;
  500.             }
  501.  
  502.             
  503.         CopyMem((char * )&mgetNGad[ lc ], (char * )ng, (long)sizeof( struct NewGadget ));
  504.  
  505.         ng->ng_VisualInfo = VisualInfo;
  506.         ng->ng_TextAttr   = &listfont;
  507.         ng->ng_LeftEdge   = offx;
  508.       ng->ng_TopEdge    = topedge[lc];
  509.         ng->ng_Width      = wwidth - offx;
  510.       ng->ng_Height     = height[lc];    
  511.        ng->ng_GadgetText = NULL;
  512.         ng->ng_Flags        = NULL;
  513.         ng->ng_GadgetID   = lc + 50;
  514.  
  515.         mgetGadgets[ lc ] = gadlist = CreateGadget(LISTVIEW_KIND, gadlist, ng, GTLV_Top, 0, TAG_END);
  516.         
  517.         while( mgetGTags[ tc ] ) tc += 2;
  518.         tc++;
  519.  
  520.         if ( NOT gadlist)
  521.         {
  522.             return( 2L );
  523.         }
  524.     }
  525. }
  526.  
  527.  
  528.  
  529.  
  530.  
  531.  
  532.  
  533.  
  534.  
  535. int OpenmgetWindow( void)
  536. {
  537.     struct NewGadget ng;
  538.     struct Gadget    *g;
  539.     int titleheight = (Scr->WBorTop + Scr->RastPort.TxHeight + 1);
  540.     int nMinHeight;
  541.     
  542.     if (nListFontSize == 0) nListFontSize = listfont.ta_YSize;    /* get default setting */
  543.     
  544.     nMinHeight = (8 * (nListFontSize + 2));
  545.     if (nMinHeight < 90) nMinHeight = 90;
  546.     nMinHeight += titleheight;
  547.   
  548.     if ((windowwidth <= 0)||(windowwidth > screenwidth)) windowwidth  = screenwidth;
  549.     if (windowheight < nMinHeight) windowheight = nMinHeight;
  550.     
  551.     if ((windowheight <= 0)||(windowheight > screenheight)) windowheight = screenheight - titleheight;
  552.             
  553.     if ((windowleft <= 0)||(windowleft > screenwidth))        windowleft   = 0;
  554.     if ((windowleft+windowwidth) > screenwidth)    windowwidth -= windowleft;
  555.     if ((windowtop <= 0)||(windowtop > screenheight))       windowtop    = titleheight;
  556.     if ((windowtop+windowheight) > screenheight) windowheight -= windowtop;
  557.         
  558.     if ((windowwidth <= 0)||(windowwidth > screenwidth))    
  559.         {
  560.         windowwidth  = screenwidth;
  561.         windowleft = 0;
  562.         }
  563.         
  564.     if ((windowheight <= 0)||(windowheight > screenheight)) 
  565.         {
  566.         windowheight = screenheight - titleheight;
  567.         windowtop = titleheight;
  568.         }
  569.         
  570.     
  571.     if (SetupGadgets(g, &ng) == 2L) return(2L);    
  572.     
  573.     if ( ! ( mgetMenus = CreateMenus( mgetNewMenu, GTMN_FrontPen, 0L, TAG_DONE )))
  574.         return( 3L );
  575.     
  576.     LayoutMenus( mgetMenus, VisualInfo, TAG_DONE );    
  577.         
  578.     switch (screentype)
  579.         {
  580.         case USE_PUBSCREEN:
  581.             if ( ! ( mgetWnd = OpenWindowTags( NULL,
  582.                 WA_Left,        windowleft,
  583.                 WA_Top,        windowtop,
  584.                 WA_Width,         windowwidth,
  585.                 WA_Height,    windowheight,
  586.                 WA_PubScreen,    Scr,
  587.                 WA_PubScreenFallBack, TRUE,
  588.                 WA_IDCMP,    LISTVIEWIDCMP|IDCMP_MENUPICK|IDCMP_CLOSEWINDOW|IDCMP_REFRESHWINDOW|IDCMP_NEWSIZE|IDCMP_RAWKEY|IDCMP_VANILLAKEY,
  589.                 WA_Flags,    WFLG_SIZEGADGET|WFLG_SIZEBBOTTOM|WFLG_DRAGBAR|WFLG_DEPTHGADGET|WFLG_CLOSEGADGET|WFLG_SMART_REFRESH|WFLG_ACTIVATE|WFLG_NEWLOOKMENUS,
  590.                 WA_Gadgets,    mgetGList,
  591.                 WA_Title,         windowtitle,
  592.                 WA_ScreenTitle,pnamestring,
  593.                 WA_MinWidth,    155,
  594.                 WA_MinHeight,    nMinHeight,
  595.                 WA_MaxWidth,    -1,
  596.                 WA_MaxHeight,    -1,
  597.                 TAG_DONE )))    
  598.                     return( 4L );
  599.             break;
  600.             
  601.         case USE_CUSTOMSCREEN:
  602.             if ( ! ( mgetWnd = OpenWindowTags( NULL,
  603.                 WA_Left,        windowleft,
  604.                 WA_Top,        windowtop,
  605.                 WA_Width,         windowwidth,
  606.                 WA_Height,    windowheight,
  607.                 WA_CustomScreen,    Scr,
  608.                 WA_IDCMP,    LISTVIEWIDCMP|IDCMP_MENUPICK|IDCMP_CLOSEWINDOW|IDCMP_REFRESHWINDOW|IDCMP_NEWSIZE|IDCMP_RAWKEY|IDCMP_VANILLAKEY,
  609.                 WA_Flags,    WFLG_SIZEGADGET|WFLG_SIZEBBOTTOM|WFLG_DRAGBAR|WFLG_DEPTHGADGET|WFLG_CLOSEGADGET|WFLG_SMART_REFRESH|WFLG_ACTIVATE|WFLG_NEWLOOKMENUS|WFLG_NEWLOOKMENUS|WFLG_NEWLOOKMENUS|WFLG_NEWLOOKMENUS,
  610.                 WA_Gadgets,    mgetGList,
  611.                 WA_Title,         windowtitle,
  612.                 WA_ScreenTitle,pnamestring,
  613.                 WA_MinWidth,    155,
  614.                 WA_MinHeight,    nMinHeight,
  615.                 WA_MaxWidth,    -1,
  616.                 WA_MaxHeight,    -1,
  617.                 TAG_DONE )))    
  618.                     return( 4L );
  619.             break;
  620.             
  621.         case USE_WBSCREEN:
  622.             if ( ! ( mgetWnd = OpenWindowTags( NULL,
  623.                 WA_Left,        windowleft,
  624.                 WA_Top,        windowtop,
  625.                 WA_Width,         windowwidth,
  626.                 WA_Height,    windowheight,
  627.                 WA_IDCMP,    LISTVIEWIDCMP|IDCMP_MENUPICK|IDCMP_CLOSEWINDOW|IDCMP_REFRESHWINDOW|IDCMP_NEWSIZE|IDCMP_RAWKEY|IDCMP_VANILLAKEY,
  628.                 WA_Flags,    WFLG_SIZEGADGET|WFLG_SIZEBBOTTOM|WFLG_DRAGBAR|WFLG_DEPTHGADGET|WFLG_CLOSEGADGET|WFLG_SMART_REFRESH|WFLG_ACTIVATE|WFLG_NEWLOOKMENUS,
  629.                 WA_Gadgets,    mgetGList,
  630.                 WA_Title,         windowtitle,
  631.                 WA_ScreenTitle,pnamestring,
  632.                 WA_MinWidth,    155,
  633.                 WA_MinHeight,    nMinHeight,
  634.                 WA_MaxWidth,    -1,
  635.                 WA_MaxHeight,    -1,
  636.                 TAG_DONE )))    
  637.                     return( 4L );
  638.                     
  639.             if (appwindow == 1)
  640.                 {
  641.                 awport = CreateMsgPort();
  642.                 if (awport == NULL) 
  643.                     {
  644.                     appwindow = 0;
  645.                     return(4L);
  646.                     }
  647.  
  648.                 appwin = AddAppWindow(1, 0, mgetWnd, awport, NULL);
  649.                 
  650.                 if (appwin == NULL)
  651.                     {appwindow = 0;}
  652.                     else
  653.                     appwinsig = 1L << awport->mp_SigBit;
  654.                 }
  655.                 
  656.             break;
  657.         }    
  658.  
  659.     TurnOnAllMenuItems(mgetMenus);
  660.     SetMenuStrip( mgetWnd, mgetMenus ); 
  661.     GT_RefreshWindow( mgetWnd, NULL );
  662. return( 0L );
  663. }
  664.  
  665.  
  666.  
  667.  
  668.  
  669.  
  670.  
  671. void ClosemgetWindow( void )
  672. {
  673.     if ( mgetMenus      ) {
  674.         ClearMenuStrip( mgetWnd );
  675.         FreeMenus( mgetMenus );
  676.         mgetMenus = NULL;    }
  677.  
  678.     if ( findwindow     ) { 
  679.          CloseWindow( findwindow );
  680.          FreeGadgets(findgadlist);
  681.          FreeVisualInfo(findvi);
  682.          findwindow = NULL;
  683.          }
  684.      
  685.      if (appwin) {
  686.          RemoveAppWindow(appwin);
  687.          
  688.          /* throw out any leftover messages */
  689.          while(amsg = (struct AppMessage *) GetMsg(awport))
  690.                  ReplyMsg((struct Message *) amsg);
  691.          DeleteMsgPort(awport);
  692.          }
  693.         
  694.     if ( mgetWnd        ) {
  695.         CloseWindow( mgetWnd );
  696.         windowisopen = 0;
  697.         mgetWnd = NULL;
  698.         }
  699.  
  700.     if ( mgetGList      ) {
  701.         FreeGadgets( mgetGList );
  702.         mgetGList = NULL;
  703.         }
  704. }
  705.  
  706.  
  707. #endif
  708.  
  709.